home *** CD-ROM | disk | FTP | other *** search
- /****
- * CQTDoc.c
- *
- * Document methods for the QuickTime Demo application.
- *
- * Copyright © 1992 Joe Zobkiw. All rights reserved.
- * Portions Copyright © 1990 Symantec Corporation. All rights reserved.
- *
- * This document method doesn't deal with files all that much
- * since we are a very simple demo.
- *
- ****/
-
- #include "Global.h"
- #include "Commands.h"
- #include "CApplication.h"
- #include "CBartender.h"
- #include "CDataFile.h"
- #include "CDecorator.h"
- #include "CDesktop.h"
- #include "CError.h"
- #include "CPanorama.h"
- #include "CScrollPane.h"
- #include "CQTDoc.h"
- #include "CQTPane.h"
- #include "TBUtilities.h"
- #include "CWindow.h"
- #include <Packages.h>
- #include "QuickTime Utilities.h"
- #include "Defines.h"
-
- #define WINDQT 500 /* Resource ID for WIND template */
-
- extern CBartender *gBartender; /* The menu handling object */
- extern CDecorator *gDecorator; /* Window dressing object */
- extern CDesktop *gDesktop; /* The enclosure for all windows */
-
- /***
- * IQTDoc
- *
- * This is your document's initialization method.
- * If your document has its own instance variables, initialize
- * them here.
- *
- * The least you need to do is invoke the default method.
- *
- ***/
-
-
- void CQTDoc::IQTDoc(CApplication *aSupervisor, Boolean printable)
-
- {
- CDocument::IDocument(aSupervisor, printable);
- }
-
-
- /***
- * Dispose
- *
- * This is your document's destruction method.
- * If you allocated memory in your initialization method
- * or opened temporary files, this is the place to release them.
- *
- * Be sure to call the default method!
- *
- ***/
-
- void CQTDoc::Dispose()
-
- {
- inherited::Dispose();
- }
-
-
- /***
- * DoCommand
- *
- * This is the heart of your document.
- * In this method, you handle all the commands your document
- * deals with.
- *
- ***/
-
- void CQTDoc::DoCommand(long theCommand)
-
- {
- switch (theCommand) {
-
- case kImportMovieItem: {
- FSSpec spec;
- if (GetMovieFileFSSpec(&spec)) {
- ((CQTPane*)itsMainPane)->ImportMovie(&spec);
- itsWindow->SetTitle(spec.name);
- }
- }
- break;
-
- default: inherited::DoCommand(theCommand);
- break;
- }
- }
-
-
- /***
- * UpdateMenus
- *
- * In this method you can enable menu commands that apply when
- * your document is active.
- *
- * Be sure to call the inherited method to get the default behavior.
- * The inherited method enables these commands: cmdClose, cmdSaveAs,
- * cmdSave, cmdRevert, cmdPageSetup, cmdPrint, cmdUndo.
- *
- ***/
-
- void CQTDoc::UpdateMenus()
-
- {
- inherited::UpdateMenus();
-
- /* Enable your menu commands here (enable each one with a call to
- gBartender->EnableCmd(command_number)).
- */
-
- gBartender->EnableCmd(kImportMovieItem);
- }
-
- /***
- * NewFile
- *
- * When the user chooses New from the File menu, the CreateDocument()
- * method in your Application class will send a newly created document
- * this message. This method needs to create a new window, ready to
- * work on a new document.
- *
- * Since this method and the OpenFile() method share the code for creating
- * the window, you should use an auxiliary window-building method.
- *
- ***/
- void CQTDoc::NewFile(void)
-
- {
- Str255 wTitle; /* Window title string. */
- short wCount; /* Index number of new window. */
- Str255 wNumber; /* Index number as a string. */
-
- BuildWindow(NULL); // we have no spec here.
-
- /**
- ** Append an index number to the
- ** default name of the window.
- **/
-
- itsWindow->GetTitle(wTitle);
- wCount = gDecorator->GetWCount();
- NumToString(wCount, wNumber);
- ConcatPStrings(wTitle, (StringPtr) "\p ");
- ConcatPStrings(wTitle, wNumber);
- itsWindow->SetTitle(wTitle);
- itsWindow->Select();
- }
-
- /***
- * OpenQTFile
- *
- * Opens the movie file into a window
- *
- ***/
-
- void CQTDoc::OpenQTFile(FSSpec *movieSpec)
- {
- BuildWindow(movieSpec);
- itsWindow->SetTitle(movieSpec->name);
- itsWindow->Select();
- }
-
- /***
- * BuildWindow
- *
- * This is the auxiliary window-building method that the
- * NewFile() and OpenFile() methods use to create a window.
- *
- * In this implementation, the argument is the data to display.
- *
- ***/
-
- void CQTDoc::BuildWindow (FSSpec *movieSpec)
-
- {
- CScrollPane *theScrollPane;
- CQTPane *theMainPane;
-
- /**
- ** First create the window and initialize
- ** it. The first argument is the resource ID
- ** of the window. The second argument specifies
- ** whether the window is a floating window.
- ** The third argument is the window's enclosure; it
- ** should always be gDesktop. The last argument is
- ** the window's supervisor in the Chain of Command;
- ** it should always be the Document object.
- **
- **/
-
- itsWindow = new(CWindow);
- itsWindow->IWindow(WINDQT, FALSE, gDesktop, this);
-
- /**
- ** After you create the window, you can use the
- ** SetSizeRect() message to set the window’s maximum
- ** and minimum size. Be sure to set the max & min
- ** BEFORE you send a PlaceNewWindow() message to the
- ** decorator.
- **
- ** The default minimum is 100 by 100 pixels. The
- ** default maximum is the bounds of GrayRgn() (The
- ** entire display area on all screens.)
- **
- ** We'll use the defaults.
- **
- **/
-
- /**
- ** Our window will contain a ScrollPane,
- ** which in turn will contain a Panorama.
- ** Now, let's create the ScrollPane.
- **/
-
- theScrollPane = new(CScrollPane);
-
- /**
- ** You can initialize a scroll pane two ways:
- ** 1. You can specify all the values
- ** right in your code, like this.
- ** 2. You can create a ScPn resource and
- ** initialize the pane from the information
- ** in the resource.
- **
- **/
-
- theScrollPane->IScrollPane(itsWindow, this, 10, 10, 0, 0,
- sizELASTIC, sizELASTIC,
- TRUE, TRUE, TRUE);
-
- /**
- ** The FitToEnclFrame() method makes the
- ** scroll pane be as large as its enclosure.
- ** In this case, the enclosure is the window,
- ** so the scroll pane will take up the entire
- ** window.
- **
- **/
-
- theScrollPane->FitToEnclFrame(TRUE, TRUE);
-
-
- /**
- ** itsMainPane is the document's focus
- ** of attention. Some of the standard
- ** classes (particularly CPrinter) rely
- ** on itsMainPane pointing to the main
- ** pane of your window.
- **
- ** itsGopher specifies which object
- ** should become the gopher when the document
- ** becomes active. By default
- ** the document becomes the gopher. It’s
- ** likely that your main pane handles commands
- ** so you’ll almost always want to set itsGopher
- ** to point to the same object as itsMainPane.
- **
- ** Note that the main pane is the
- ** panorama in the scroll pane and not
- ** the scroll pane itself.
- **
- **/
-
- theMainPane = new(CQTPane);
- theMainPane->IQTPane(theScrollPane, this, 0, 0, 0, 0, sizELASTIC, sizELASTIC, movieSpec);
- itsMainPane = theMainPane;
- itsGopher = theMainPane;
-
- /** The FitToEnclosure() method makes the pane
- ** fit inside the enclosure. The inside (or
- ** interior) of a scroll pane is defined as
- ** the area inside the scroll bars.
- **/
-
- theMainPane->FitToEnclosure(TRUE, TRUE);
-
- /**
- ** Send the scroll pane an InstallPanorama()
- ** message to associate the panorama with
- ** the scroll pane.
- **
- **/
-
- theScrollPane->InstallPanorama(theMainPane);
-
- /**
- ** The Decorator is a global object that takes care
- ** of placing and sizing windows on the screen.
- ** You don't have to use it.
- **
- **/
-
- gDecorator->PlaceNewWindow(itsWindow);
- }
-
-